package com.tracking.locon;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ContactAdapter extends ArrayAdapter<ContactOne>{

	Context mContext; 
    int mLayoutResourceId;    
    ContactOne mData[] = null;
	
	public ContactAdapter(Context context, int layoutResourceId,
			ContactOne[] data) {
		super(context, layoutResourceId, data);
		mContext = context;
		mLayoutResourceId = layoutResourceId;;
		mData = data;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ContactHolder holder = null;
        
        if(row == null)
        {
            LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
            row = inflater.inflate(mLayoutResourceId, parent, false);
            
            holder = new ContactHolder();
            holder.ivPhoto = (ImageView)row.findViewById(R.id.ivContactPhoto);
            holder.tvName = (TextView)row.findViewById(R.id.tvContactName);
            holder.tvInfo = (TextView)row.findViewById(R.id.tvContactInfo);
            
            row.setTag(holder);
        }
        else
        {
            holder = (ContactHolder)row.getTag();
        }
        
        ContactOne contactOne = mData[position];
        
        holder.ivPhoto.setImageResource(contactOne.mPhoto);
        holder.tvName.setText(contactOne.mName);
        holder.tvInfo.setText(contactOne.mInfo);
        
        return row;
    }
	
	public static class ContactHolder
    {
        ImageView ivPhoto;
        TextView tvName;
        TextView tvInfo;
    }

}
